//
//  OutputMemoryStream.cpp
//  MultiPlayer
//
//  Created by 星落之尘 on 2020/6/10.
//  Copyright © 2020 Tan. All rights reserved.
//

#include "OutputMemoryStream.h"
#include "RoboCatPCH.h"
using namespace std;

void OutputMemoryStream::ReallocBuffer(u_int32_t inNewLength)
{
    mBuffer = static_cast<char*>(realloc(mBuffer, inNewLength));
    mCapacity = inNewLength;
}



void OutputMemoryStream::Write(const void *inData, size_t inByteCount)
{
    uint32_t resultHead = mHead + static_cast<uint32_t>(inByteCount);
    if (resultHead > mCapacity) {
        ReallocBuffer(std::max(mCapacity * 2, resultHead));
    }
    
  
    std::memcpy(mBuffer + mHead, inData, inByteCount);
    
    mHead = resultHead;
}






